package com.sugon.controller.basics;

import com.sugon.annotation.AutoLog;
import com.sugon.entity.PlanNeedCheckEntity;
import com.sugon.service.PlanNeedCheckService;
import com.sugon.utils.PageUtils;
import com.sugon.utils.Query;
import com.sugon.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 需求计划审批Controller
 *
 * @author sugon
 * @date 2019-08-13 10:50:10
 */
@Controller
@RequestMapping("planneedcheck")
public class PlanNeedCheckController {
    @Autowired
    private PlanNeedCheckService planNeedCheckService;

    /**
     * 查看列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("planneedcheck:list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params) {
        //查询列表数据
        Query query = new Query(params);

        List<PlanNeedCheckEntity> planNeedCheckList = planNeedCheckService.queryList(query);
        int total = planNeedCheckService.queryTotal(query);

        PageUtils pageUtil = new PageUtils(planNeedCheckList, total, query.getLimit(), query.getPage());

        return R.ok().put("page", pageUtil);
    }

    /**
     * 查看信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("planneedcheck:info")
    @ResponseBody
    public R info(@PathVariable("id") String id) {
        PlanNeedCheckEntity planNeedCheck = planNeedCheckService.queryObject(id);

        return R.ok().put("planNeedCheck", planNeedCheck);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("planneedcheck:save")
    @ResponseBody
    public R save(@RequestBody PlanNeedCheckEntity planNeedCheck) {
        planNeedCheckService.save(planNeedCheck);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("planneedcheck:update")
    @ResponseBody
    public R update(@RequestBody PlanNeedCheckEntity planNeedCheck) {
        planNeedCheckService.update(planNeedCheck);

        return R.ok();
    }

    /**
     * 车间审批
     */
    @RequestMapping("/deptCheck")
    @RequiresPermissions("planneedcheck:deptCheck")
    @ResponseBody
    public R deptCheck(@RequestBody PlanNeedCheckEntity planNeedCheck) {
        planNeedCheckService.deptCheck(planNeedCheck);

        return R.ok();
    }

    /**
     * 制造处审批
     */
    @RequestMapping("/makeCheck")
    @RequiresPermissions("planneedcheck:makeCheck")
    @ResponseBody
    public R makeCheck(@RequestBody PlanNeedCheckEntity planNeedCheck) {
        planNeedCheckService.makeCheck(planNeedCheck);

        return R.ok();
    }

    /**
     * 综合审批
     */
    @RequestMapping("/leaderCheck")
    @RequiresPermissions("planneedcheck:leaderCheck")
    @ResponseBody
    public R leaderCheck(@RequestBody PlanNeedCheckEntity planNeedCheck) {
        planNeedCheckService.leaderCheck(planNeedCheck);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("planneedcheck:delete")
    @ResponseBody
    public R delete(@RequestBody String[] ids) {
        planNeedCheckService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 查看所有列表
     */
    @RequestMapping("/queryAll")
    @ResponseBody
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<PlanNeedCheckEntity> list = planNeedCheckService.queryList(params);

        return R.ok().put("list", list);
    }
}
